package net.sxnic.ugr.user.util;

import java.util.List;
import java.util.Set;

import net.sxnic.ugr.user.User;

import org.apache.commons.lang.StringUtils;

public class UserUtils {
	
	public static String createCheckboxHtml(Set<User> users,
			List<User> allusers, String name) {

		StringBuffer sb = new StringBuffer();

		String temp = ",";
		for (User u : users) {
			temp = temp + u.getUsername() + ",";
		}
  
		
		int i=0;
        String lstrbr="";
		 
			
		for (User u : allusers) {
			i++;
			lstrbr=i%3==0?"<br>":"";
			if (StringUtils.contains(temp,","+u.getUsername()+",")) {
				sb.append("<input type='checkbox' name='" + name + "' value='"
						+ u.getUsername() + "' checked='true' />&nbsp;"
						+ u.getUsername() +u.getFullname()+ "&nbsp;"+lstrbr);
			} else {
				sb.append("<input type='checkbox' name='" + name + "' value='"
						+ u.getUsername() + "' />&nbsp;" + u.getUsername()+u.getFullname() + "&nbsp;"+lstrbr);
			}
		}

		return sb.toString();

	}

}
